namespace Chaliy.Syndication.MediaRss
{
	using System;
	using System.Xml;
	using System.Xml.Schema;
	using System.Xml.Serialization;
    using System.Runtime.Serialization;

	/// <summary>
    /// 	Raitng allows the permissible audience to be declared. If this element is not included, it assumes that no restrictions are necessary.
	/// </summary>
    [XmlRoot("rating", Namespace = Namespaces.MediaRssPrivate)]
    public sealed class MediaRating : IXmlSerializable
    {
    	/// <summary>
        /// 	Get or set the scheme of the raiting, which is the URI that identifies the rating scheme. It is an optional attribute. If this attribute is not included, the default scheme is urn:simple (adult | nonadult).
    	/// </summary>
        public string Scheme
        {
            get;
            set;
        }

        public string Value
        {
            get;
            set;
        }

        #region IXmlSerializable Members

        XmlSchema IXmlSerializable.GetSchema()
        {
            throw new NotSupportedException(); // TODO Implement
        }

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            throw new NotSupportedException(); // TODO Implement
        }

        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            ArgumentUtilities.EnsureArgumentNotNull(writer, "writer");

            // Simple schema is default value, so this is no reason to write it down
            if (MediaRatingSimpleSchema.Identifier
                .Equals(this.Scheme, StringComparison.OrdinalIgnoreCase) == false)
            {
                writer.WriteStringAttribute("scheme", this.Scheme);
            }

            if (String.IsNullOrEmpty(this.Value) == false)
            {
                writer.WriteValue(this.Value);
            }
        }

        #endregion
    }

}
